﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DHQGHN.DAL.Common;
using DHQGHN.DAL.DAO.Admin;
using DHQGHN.DAL.Models.Admin;
namespace DHQGHN.DAL.BO.Admin
{
   public class RelationBO: BaseBO
    {
        #region
        public const string FIELD_RELATION_ID = "RELATION_ID";
        public const string FIELD_CODE = "CODE";
        public const string FIELD_NAME = "NAME";
        public const string FIELD_DESCRIPTIONS = "DESCRIPTIONS";
        public const string FIELD_DELETED = "DELETED";
        #endregion
        public const string FIELD_RECORD_COUNT = "RecordCount";
        private String _connectionString;

        public RelationBO(string connString)
        {
            this._connectionString = connString;
        }

        public RelationBO()
        {
            this._connectionString = Common.ConnectionUtil.TKTHDS_METADATA_CONNECTION_STRING;

        }

        public RelationDAO _RelationDAO;
        public RelationDAO CreateSQLDAO()
        {
            return new RelationDAO(_connectionString, DEFAULT_MAPPER_TYPE);
        }

        public RelationBO(string _connectionString, Type DEFAULT_MAPPER_TYPE)
        {
            // TODO: Complete member initialization

            this.DEFAULT_MAPPER_TYPE = DEFAULT_MAPPER_TYPE;
        }


        public DataPage<RelationModel> GetDynamicListPaging(RelationModel aModel, int pageSize, int pageIndex, bool compareEqual)
        {
            try
            {
                _RelationDAO = CreateSQLDAO();
                Dictionary<String, String> mapDictionary = new Dictionary<string, string>()
                {
                    {RelationModel.FIELD_RELATION_ID,FIELD_RELATION_ID},
                    {RelationModel.FIELD_NAME,FIELD_NAME},
                    {RelationModel.FIELD_CODE,FIELD_CODE},  
                    {RelationModel.FIELD_DESCRIPTIONS,FIELD_DESCRIPTIONS},
                    {RelationModel.FIELD_DELETED,FIELD_DELETED},
                    {RelationModel.FIELD_RECORD_COUNT, FIELD_RECORD_COUNT}
                };
                return _RelationDAO.GetDynamicListPaging(aModel, pageSize, pageIndex,mapDictionary, compareEqual);
            }
            catch (Exception)
            {
                throw;
            }
        }
        public RelationModel GetRelationById(string id)
        {
            try
            {
                _RelationDAO = CreateSQLDAO();

                Dictionary<String, String> mapDictionary = new Dictionary<string, string>()
                {
                    {RelationModel.FIELD_RELATION_ID,FIELD_RELATION_ID},
                    {RelationModel.FIELD_NAME,FIELD_NAME},
                    {RelationModel.FIELD_CODE,FIELD_CODE},  
                    {RelationModel.FIELD_DESCRIPTIONS,FIELD_DESCRIPTIONS},
                    {RelationModel.FIELD_DELETED,FIELD_DELETED},
                    {RelationModel.FIELD_RECORD_COUNT, FIELD_RECORD_COUNT}
                };

                return _RelationDAO.GetById(id, mapDictionary);
            }
            catch (Exception)
            {
                throw;
            }
        }

        public bool createOrUpdateRelation(RelationModel model)
        {
            try
            {
                _RelationDAO = CreateSQLDAO();
                return _RelationDAO.createOrUpdateRelation(model);
            }
            catch (Exception e)
            {
                return false;
            }
        }

        public bool deleteRelation(string[] ID)
        {
            try
            {
                _RelationDAO = CreateSQLDAO();
                return _RelationDAO.deleteRelation(ID);
            }
            catch (Exception e)
            {
                return false;
            }
        }
    }
}
    